# https://docs.gunicorn.org/en/stable/settings.html#config
import os  # noqa
from pathlib import Path

project_path = Path(__file__).resolve().parent.parent

debug = False
# 是否是守护进程（后台运行）
#daemon = True
# 执行追踪
spew = False
# 监听文件变化重启
reload = False

# 监听
bind = "0.0.0.0:5010"
# 工作目录
chdir = str(project_path.absolute())

# 进程前缀
proc_name = "adp_v2.0_feature"
# pid文件位置
pidfile = "logs/gunicorn.pid"

x_forwarded_for_header = "X-FORWARDED-FOR"

# 启动的进程数
workers = 2
# 指定每个进程开启的线程数
threads = 1

# worker_class = "uvicorn_worker.SQUvicornWorker"  # 重载uvicorn worker
# worker_class = "gunicorn.workers.gevent.GeventWorker"  # 协程模式
# worker_class = 'uvicorn.workers.UvicornWorker'  # 原生uvicorn模式

worker_class = "gevent"

# worker在重新启动之前将处理的最大请求数 0 禁止自动重启
max_requests = 40
# max_requests 抖动
max_requests_jitter = 200
# 未工作的worker沉默timeout后重启
timeout = 300
# 重启前给予该时间完成工作
graceful_timeout = 30
# 等待链接秒数
keepalive = 5

# 日志级别
loglevel = "info"
# 合并日志
capture_output = True
# 访问日志文件
accesslog = str(project_path / "logs/gunicorn_access.log")
# 错误日志文件
errorlog = str(project_path / "logs/gunicorn_error.log")
# 设置gunicorn访问日志格式，错误日志无法设置
access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s "%(f)s" "%(a)s"'
